-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: access-api uses DID env variable when building its ucanto server id #275
Conversation
…o configureSigner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks
packages/access-api/src/config.js
Outdated
export function configureSigner(config) { | ||
const signer = Signer.parse(config.PRIVATE_KEY) | ||
if (config.DID) { | ||
if (!isDID(config.DID)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may be better to use existing functionality for this, for example this will parse and throw if it's invalid:
DID.match({ method: 'web' }).from(config.DID)
It will also take care of refusing did:key
which would be invalid in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/access-api/src/config.js
Outdated
if (parts[0] !== 'did') return false | ||
return true | ||
try { | ||
return Boolean(DID.match({}).from(object)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What’s the point of catching here to then throw ? You can simply just do .from instead of whole isDID thing.
Alternatively there’s also .is method which you could instead which will return boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 5184a55
@@ -42,12 +41,12 @@ export function getContext(request, env, ctx) { | |||
env: config.ENV, | |||
}) | |||
|
|||
const keypair = Signer.parse(config.PRIVATE_KEY) | |||
const signer = configureSigner(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you do this inside the loadConfig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 b9533c9
const url = new URL(request.url) | ||
const db = new D1QB(config.DB) | ||
return { | ||
log, | ||
signer: keypair, | ||
signer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signer, | |
signer: Signer.parse(config.PRIVATE_KEY).withDID(config.ENV === 'production' ? 'did:web:ucan.web3.storage': `did:web:ucan-${config.ENV}.web3.storage`), |
can't we just do this ? any error will be caught at dev time or CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want the advertised DID to come from env variable. A '.web3.storage' domain won't be the best choice 100% of the times, e.g. on localhost or testing various scenarios. env variable gives me flexibility to get something working. once something works/tests end to end, can narrow down the configurability.
environment: { | ||
...process.env, | ||
PRIVATE_KEY: | ||
'MgCYWjE6vp0cn3amPan2xPO+f6EZ3I+KwuN1w2vx57vpJ9O0Bn4ci4jn8itwc121ujm7lDHkCW24LuKfZwIdmsifVysY=', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need a new key here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't. Good catch. 🙏 d204331
@@ -49,6 +55,9 @@ export function loadConfig(env) { | |||
// eslint-disable-next-line no-undef | |||
COMMITHASH: ACCOUNT_COMMITHASH, | |||
|
|||
DID, | |||
signer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get the did:key and did:web from the signer instance ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log('signer did', signer.did().toString())
signer did did:web:exampe.com
console.log('signer archive', signer.toArchive())
signer archive {
id: 'did:web:exampe.com',
keys: {
'did:key:z6MkqBzPG7oNu7At8fktasQuS7QR7Tj7CujaijPMAgzdmAxD': Ed25519Signer(68) [Uint8Array] [
128, 38, 22, 140, 78, 175, 167, 71, 39, 221, 169,
143, 106, 125, 177, 60, 239, 159, 232, 70, 119, 35,
226, 176, 184, 221, 112, 218, 252, 121, 238, 250, 73,
244, 237, 1, 159, 135, 34, 226, 57, 252, 138, 220,
28, 215, 109, 110, 142, 110, 229, 12, 121, 2, 91,
110, 11, 184, 167, 217, 192, 135, 102, 178, 39, 213,
202, 198
]
}
}
packages/access-api/src/config.js
Outdated
return { | ||
DEBUG: boolValue(vars.DEBUG), | ||
ENV: parseRuntimeEnv(vars.ENV), | ||
|
||
PRIVATE_KEY: vars.PRIVATE_KEY, | ||
PRIVATE_KEY, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably dont need this one anymore right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🤖 I have created a release *beep* *boop* --- ## [4.0.0](access-api-v3.0.0...access-api-v4.0.0) (2022-12-13) ### ⚠ BREAKING CHANGES * upgrade access-api @ucanto/* and @ipld/dag-ucan major versions ([#246](#246)) * access-client store decoupling ([#228](#228)) * upgrade to `@ucanto/{interface,principal}`@^4.0.0 ([#238](#238)) * follow up on the capabilities extract ([#239](#239)) * doc capabilities & make requierd nb non-optionals ([#159](#159)) * Remove 0.8 caps and add account delegation to the service ([#123](#123)) * bump to 0.9 ([#116](#116)) ### Features * [#153](#153) ([#177](#177)) ([d6d448c](d6d448c)) * access-api uses DID env variable when building its ucanto server id ([#275](#275)) ([311da78](311da78)) * **access-client:** cli and recover ([#207](#207)) ([adb3a8d](adb3a8d)) * account recover with email ([#149](#149)) ([6c659ba](6c659ba)) * bump to 0.9 ([#116](#116)) ([3e0b63f](3e0b63f)) * doc capabilities & make requierd nb non-optionals ([#159](#159)) ([6496773](6496773)) * follow up on the capabilities extract ([#239](#239)) ([ef5e779](ef5e779)) * Remove 0.8 caps and add account delegation to the service ([#123](#123)) ([878f8c9](878f8c9)), closes [#117](#117) [#121](#121) * Revert "feat!: upgrade to `@ucanto/{interface,principal}`@^4.0.0" ([#245](#245)) ([c182bbe](c182bbe)) * sync encode/decode delegations ([#276](#276)) ([ab981fb](ab981fb)) * upgrade access-api @ucanto/* and @ipld/dag-ucan major versions ([#246](#246)) ([5e663d1](5e663d1)) * upgrade to `@ucanto/{interface,principal}`@^4.0.0 ([#238](#238)) ([2f3bab8](2f3bab8)) ### Bug Fixes * 0.9 ([#78](#78)) ([1b1ed01](1b1ed01)) * add validation copy ([#257](#257)) ([7f50af4](7f50af4)), closes [#139](#139) * fix Access API cannot get space/info [#243](#243) ([#255](#255)) ([1bacd54](1bacd54)) * fix d1 migrations ([#264](#264)) ([fb8c09d](fb8c09d)) * make d1 spaces.metadata nullable and change to kysely ([#284](#284)) ([c8a9ce5](c8a9ce5)), closes [#280](#280) * make multiformats 9 go away ([#133](#133)) ([2668880](2668880)) * miniflare dev script ([#137](#137)) ([1c5a4e2](1c5a4e2)) * testing staging deploy ([3d500fa](3d500fa)) * try to deploy api staging ([18b7b29](18b7b29)) * try to deploy staging ([c616818](c616818)) ### Code Refactoring * access-client store decoupling ([#228](#228)) ([a785278](a785278)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
…r id (#275) Motivation: * #237 Notes * This is intended to be safe to merge/deploy as is. The new functionality can be opted-into via env vars * The ucanto server will only be constructed with an opts.id that is a signer `withDID(...)` iff `process.env.DID` is set to a DID * If `process.env.DID` is unset, the ucanto server id signer will have a `did()` corresponding to `config.PRIVATE_KEY` (it will be a `did:key` of the corresponding public key) * Before this PR, many tests of the access-api worker were configured implicitly via dotenv with whatever the `/.env.local` file happened to contain. I added a worker test that asserts functionality that is dependent on the details of the env vars, so I made an affordance for [tests to be able to configure the access-api worker with environment variables defined in the test case itself](https://github.com/web3-storage/w3protocol/pull/275/files#diff-e20ffc550d006747790e7b67da280446c1cd1d2d4f72ccb5df04f62cbb6423daR149).
🤖 I have created a release *beep* *boop* --- ## [4.0.0](access-api-v3.0.0...access-api-v4.0.0) (2022-12-13) ### ⚠ BREAKING CHANGES * upgrade access-api @ucanto/* and @ipld/dag-ucan major versions ([#246](#246)) * access-client store decoupling ([#228](#228)) * upgrade to `@ucanto/{interface,principal}`@^4.0.0 ([#238](#238)) * follow up on the capabilities extract ([#239](#239)) * doc capabilities & make requierd nb non-optionals ([#159](#159)) * Remove 0.8 caps and add account delegation to the service ([#123](#123)) * bump to 0.9 ([#116](#116)) ### Features * [#153](#153) ([#177](#177)) ([7fbf2a1](7fbf2a1)) * access-api uses DID env variable when building its ucanto server id ([#275](#275)) ([e8326ec](e8326ec)) * **access-client:** cli and recover ([#207](#207)) ([720dafb](720dafb)) * account recover with email ([#149](#149)) ([91ad47d](91ad47d)) * bump to 0.9 ([#116](#116)) ([29cf63c](29cf63c)) * doc capabilities & make requierd nb non-optionals ([#159](#159)) ([f6b6d06](f6b6d06)) * follow up on the capabilities extract ([#239](#239)) ([717fcaa](717fcaa)) * Remove 0.8 caps and add account delegation to the service ([#123](#123)) ([c3c58b9](c3c58b9)), closes [#117](#117) [#121](#121) * Revert "feat!: upgrade to `@ucanto/{interface,principal}`@^4.0.0" ([#245](#245)) ([197439e](197439e)) * sync encode/decode delegations ([#276](#276)) ([9d48372](9d48372)) * upgrade access-api @ucanto/* and @ipld/dag-ucan major versions ([#246](#246)) ([65d191c](65d191c)) * upgrade to `@ucanto/{interface,principal}`@^4.0.0 ([#238](#238)) ([309aff0](309aff0)) ### Bug Fixes * 0.9 ([#78](#78)) ([561c68b](561c68b)) * add validation copy ([#257](#257)) ([0bd49ce](0bd49ce)), closes [#139](#139) * fix Access API cannot get space/info [#243](#243) ([#255](#255)) ([1a74031](1a74031)) * fix d1 migrations ([#264](#264)) ([5b8a6e7](5b8a6e7)) * make d1 spaces.metadata nullable and change to kysely ([#284](#284)) ([7f09479](7f09479)), closes [#280](#280) * make multiformats 9 go away ([#133](#133)) ([cdb4109](cdb4109)) * miniflare dev script ([#137](#137)) ([f2cffb2](f2cffb2)) * testing staging deploy ([975cffc](975cffc)) * try to deploy api staging ([5130464](5130464)) * try to deploy staging ([4e56657](4e56657)) ### Code Refactoring * access-client store decoupling ([#228](#228)) ([64c7496](64c7496)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Motivation:
did:web:web3.storage
#237Notes
withDID(...)
iffprocess.env.DID
is set to a DIDprocess.env.DID
is unset, the ucanto server id signer will have adid()
corresponding toconfig.PRIVATE_KEY
(it will be adid:key
of the corresponding public key)/.env.local
file happened to contain. I added a worker test that asserts functionality that is dependent on the details of the env vars, so I made an affordance for tests to be able to configure the access-api worker with environment variables defined in the test case itself.